/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package comandaXM.utils;

import java.util.ArrayList;
import java.util.List;

import javax.swing.AbstractListModel;
import javax.swing.ComboBoxModel;
import javax.swing.event.ListDataListener;

/**
 *
 * @author xmarti
 */
public class ComboBoxModelXM extends AbstractListModel implements ComboBoxModel{
    private Object selectedItem; 
    private List<Object> list = new ArrayList<Object>(); 
    public ComboBoxModelXM (){
       
    }
    public ComboBoxModelXM (List list ){
            this.list=list;  
            
     }
    
//    public void setItem(Object anItem)throws ExceptionComandaXM  {       
//         try{
//            for(Object l:list){
//                if(anItem.equals (l) ){
//                    selectedItem= l; 
//                    break; 
//                } 
//            } 
//         }catch(java.lang.NullPointerException ex) {
//            throw new ExceptionComandaXM(ExceptionComandaXM.ERR_NullPointerException);             
//         }
//              
//    }

    @Override
    public Object getSelectedItem() {
        return selectedItem; 
    }

    @Override
    public int getSize() {
        return list.size(); 
    }

    @Override
    public Object getElementAt(int index) {
        return list.get(index); 
    }

    @Override
    public void addListDataListener(ListDataListener l) {
        
    }

    @Override
    public void removeListDataListener(ListDataListener l) {
        
    }

    @Override
    public void setSelectedItem(Object anItem) {
        try{
            for(Object l:list){
                if(anItem.equals (l) ){
                    selectedItem= l; 
                    break; 
                } 
            } 
         }catch(java.lang.NullPointerException ex) {
               selectedItem=null; 
         }
              
    }
    
}
